import express, { RequestHandler } from 'express';
import { DataStore } from './data';
import { apiGetUserInfor, apiGetUserInforDetail } from './api/users/apiGetUserInfor';
import bodyParser from 'body-parser';
import { apiPostUserInfor, apiUploadImage } from './api/users/apiPostUserInfor';
import { apiDeleteUserInfor } from './api/users/apiDeleteUserInfor';
import { apiUpdateUserInfor } from './api/users/apiUpdateUserInfor';
import { CusstomRequest, CusstomRequestHandler } from './overried/express';
import { authenticator, errorHandler, logger } from './midware';
import path from 'path';

const app = express();
const port =process.env.PORT|| 3000;


app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use("/static",express.static(path.resolve("./",'src',"publicRes") ))
app.use(errorHandler);


//routes
app.get('/', (req, res,next) => {
  res.send('get Hello, TypeScript with Express!!!');
});
app.get("/userInfor",apiGetUserInfor);
app.get("/userInfor/:id",apiGetUserInforDetail);
app.get("/todo",(req, res,next) => {
 res.json(DataStore.todo);
});


app.post("/userInfor",apiPostUserInfor)
app.post("/userInfor/:id/img",apiUploadImage)

app.delete("/userInfor/:id",apiDeleteUserInfor)

app.put("/userInfor/:id",apiUpdateUserInfor)
app.listen(port, () => {
  console.log(`Server is running on ! port ${port}!!!`);
});
